<?php

namespace Core\Utils\Authentication;

class Authentication
{
    /**
     * 实名认证接口
     * 阿里云市场身份证二要素认证
     * */
    public static function certification($truename,$idcard){
        $host = "https://eid.shumaidata.com";
        $path = "/eid/check";
        $method = "POST";
        $appcode = "0aea296d653f48f09b400dbdd2e75d46";
        $headers = array();
        array_push($headers, "Authorization:APPCODE " . $appcode);
        $querys = "idcard=$idcard&name=".urlencode($truename);
        $bodys = "";
        $url = $host . $path . "?" . $querys;
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_FAILONERROR, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        //设定返回信息中是否包含响应信息头，启用时会将头文件的信息作为数据流输出，true 表示输出信息头, false表示不输出信息头
        //如果需要将字符串转成json，请将 CURLOPT_HEADER 设置成 false
        curl_setopt($curl, CURLOPT_HEADER, false);
        if (1 == strpos("$".$host, "https://"))
        {
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        }
        $curl_exec = json_decode(curl_exec($curl),true);
        return $curl_exec["result"]["res"];
    }
}